<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <!-- a.3 配置跳转之后的出口 -->
        <router-view></router-view>
        <!-- a.2 通过router-link 创建跳转link -->
        <!-- RouterLink => a标签 => 引入 vue-router=>全局注册的组件 -->
        <router-link to="/home">主页</router-link>
        <router-link to="/introduce">公司介绍</router-link>
        <router-link to="/profile">产品详情</router-link>
    </div>
</body>
<script src="./node_modules/vue/dist/vue.js"></script>
<!-- a.1 引入 vue-router 的依赖 -->
<script src="./node_modules/vue-router/dist/vue-router.js"></script>
<!-- 
    引入 vue-router 依赖 全局 引入 对象 VueRouter
 -->
<script>
    //
    // console.log(VueRouter);
    /* a.4 定义显示的组件 */
    let Home = {
        template: `<h1>主页的内容</h1>`
    }
    let Introduce = {
        template: `<h1>公司介绍</h1>`
    }
    let Profile = {
        template: `<h1>产品详情</h1>`
    }
    /* a.5 定义组件和路由之间的关系 */
    let routes = [{
            path: "/home",
            component: Home,
            beforeEnter: (to, from, next) => {
                console.log("进入到 Home路由中");
                next();
            }
        },
        {
            path: "/introduce",
            component: Introduce
        },
        {
            path: "/profile",
            component: Profile
        }, {
            path: "/login",
            component: () => Promise.resolve({
                template: `<h1>登录</h1>`
            })
        }
    ]
    // Vue.use(VueRouter);
    /* a.6 new 路由的实例 */
    let router = new VueRouter({
        routes // 不能改 routes routes:routes
    })
    
    let vm = new Vue({
        /* a.7 */
        router,
        el: "#app"
    })
</script>

</html>